<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  

  
  <title>Java知识点--week1（基本方法，注解，ArrayList，数据过滤，Integer类，Date） | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="Java基本方法概况 System.out.println(“string”);   控制台打印信息  concat方法：拼接字符串   string1.concat(string2)  +拼接字符串  string.length()：查看字符串长度  string1.equals(string2)：返回值为布尔类型   常量12//快捷：constprivate static final St">
<meta name="keywords" content="Java">
<meta property="og:type" content="article">
<meta property="og:title" content="Java知识点--week1（基本方法，注解，ArrayList，数据过滤，Integer类，Date）">
<meta property="og:url" content="http://yoursite.com/2019/07/16/Java知识点-1/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="Java基本方法概况 System.out.println(“string”);   控制台打印信息  concat方法：拼接字符串   string1.concat(string2)  +拼接字符串  string.length()：查看字符串长度  string1.equals(string2)：返回值为布尔类型   常量12//快捷：constprivate static final St">
<meta property="og:locale" content="default">
<meta property="og:image" content="https://images2015.cnblogs.com/blog/1121163/201707/1121163-20170718205559349-30919243.jpg">
<meta property="og:updated_time" content="2019-07-20T06:52:03.555Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java知识点--week1（基本方法，注解，ArrayList，数据过滤，Integer类，Date）">
<meta name="twitter:description" content="Java基本方法概况 System.out.println(“string”);   控制台打印信息  concat方法：拼接字符串   string1.concat(string2)  +拼接字符串  string.length()：查看字符串长度  string1.equals(string2)：返回值为布尔类型   常量12//快捷：constprivate static final St">
<meta name="twitter:image" content="https://images2015.cnblogs.com/blog/1121163/201707/1121163-20170718205559349-30919243.jpg">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-Java知识点-1" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2019/07/16/Java知识点-1/" class="article-date">
  <time datetime="2019-07-16T09:21:39.000Z" itemprop="datePublished">2019-07-16</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Java/">Java</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Java知识点--week1（基本方法，注解，ArrayList，数据过滤，Integer类，Date）
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <hr>
<h2 id="Java基本方法概况"><a href="#Java基本方法概况" class="headerlink" title="Java基本方法概况"></a>Java基本方法概况</h2><ul>
<li><p>System.out.println(“string”);</p>
<p>  控制台打印信息</p>
</li>
<li><p>concat方法：拼接字符串</p>
<p>  string1.concat(string2)</p>
</li>
<li><p><code>+</code>拼接字符串</p>
</li>
<li><p>string.length()：查看字符串长度</p>
</li>
<li><p>string1.equals(string2)：返回值为布尔类型</p>
</li>
</ul>
<h3 id="常量"><a href="#常量" class="headerlink" title="常量"></a><font color="red">常量</font></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">//快捷：const</span><br><span class="line">private static final String ConStant = &quot;常量&quot;;</span><br></pre></td></tr></table></figure>

<h2 id="注解"><a href="#注解" class="headerlink" title="注解"></a>注解</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">@RestController</span><br><span class="line">public class AccountingController &#123;</span><br><span class="line">    @RequestMapping(path = &quot;/accounting&quot;)</span><br><span class="line">    public String accounting(@RequestParam(&quot;cash&quot;) int cash,@RequestParam(&quot;income&quot;) int income,@RequestParam(&quot;rent&quot;) int rent,@RequestParam(&quot;charges&quot;) int charges,</span><br><span class="line"></span><br><span class="line">    @RequestParam(&quot;eat&quot;) int eat)&#123;</span><br><span class="line">        int result = cash + income - rent - charges - eat;</span><br><span class="line">        String str = String.valueOf(result);</span><br><span class="line">        return str;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>@RestController = @Controller + @ResponseBody：</p>
<ol>
<li><p>@Controller 习惯于和@RequestMapping绑定来使用</p>
</li>
<li><p>@ResponseBody告诉控制器返回对象会被自动序列化成JSON，并且传回HttpResponse这个对象。相当于自动实现XMLHttpRequest</p>
</li>
</ol>
</li>
<li><p>@RequestMapping：为HTML的form表单提供地址</p>
</li>
<li><p>@RequestParam(“前端input的name”)：获取输入的值</p>
  <figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public String search(@RequestParam(&quot;amount&quot;) int amount)&#123;</span><br><span class="line">    return null;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="ArrayList"><a href="#ArrayList" class="headerlink" title="ArrayList"></a>ArrayList</h2><ol>
<li><p>能够动态扩容的数组</p>
</li>
<li><p>按照放入的顺序存储数据，可以存放重复的对象</p>
</li>
</ol>
<h3 id="ArrayList——方法概况"><a href="#ArrayList——方法概况" class="headerlink" title="ArrayList——方法概况"></a>ArrayList——方法概况</h3><ol>
<li><p>add：增加数据</p>
</li>
<li><p>remove：删除数据</p>
</li>
<li><p>size：长度</p>
</li>
<li><p>isEmpty：是否为空</p>
</li>
<li><p>get：获取数组中的值，根据索引读取元素，比如可以获取第二个元素</p>
</li>
</ol>
<h3 id="ArrayList——遍历数组——foreach循环"><a href="#ArrayList——遍历数组——foreach循环" class="headerlink" title="ArrayList——遍历数组——foreach循环"></a>ArrayList——遍历数组——foreach循环</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">for (String item : List1)&#123;</span><br><span class="line">    //String item : List1等价于从数组的第一个开始，自动加一</span><br><span class="line">    System.out.println(&quot;ArrayList的元素是：&quot; + item);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="Integer类"><a href="#Integer类" class="headerlink" title="Integer类"></a>Integer类</h2><p>Integer 类在对象中包装了一个基本类型int的值。Integer类型的对象包含一个 int 类型的字段。此外，该类提供了多个方法，能在 int 类型和 String 类型之间互相转换，同时还提供了其他一些处理int类型时非常有用的常量和方法。</p>
<h3 id="构造方法"><a href="#构造方法" class="headerlink" title="构造方法"></a>构造方法</h3><ol>
<li>Integer(int number)</li>
</ol>
<p>该方法以一个int型变量作为参数来获取Integer对象。<br>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Intrger number = new Integer(7);</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>Integer(String str)</li>
</ol>
<p>该方法以一个String型变量作为参数来获取Integer对象。<br>例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Intrger number = new Integer(&quot;45&quot;);</span><br></pre></td></tr></table></figure>

<ul>
<li>要用数值型String变量作为参数，如123，否则将会抛出NumberFormatException异常。</li>
</ul>
<h3 id="常用方法"><a href="#常用方法" class="headerlink" title="常用方法"></a>常用方法</h3><p><img src="https://images2015.cnblogs.com/blog/1121163/201707/1121163-20170718205559349-30919243.jpg" alt></p>
<ul>
<li><p>parseInt()方法返回与调用该方法的数值字符串相应的整型(int)值</p>
</li>
<li><p>toString()方法，可将Integer对象转换为十进制字符串表示。toBinaryString()、toHexString()和toOctalString()方法分别将值转换成二进制、十六进制和八进制字符串。</p>
</li>
</ul>
<p>详情请见：<a href="https://www.cnblogs.com/cxf1404445126/p/7202483.html" target="_blank" rel="noopener">https://www.cnblogs.com/cxf1404445126/p/7202483.html</a></p>
<h2 id="数据过滤"><a href="#数据过滤" class="headerlink" title="数据过滤"></a>数据过滤</h2><ol>
<li>Stream Filter</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">    List&lt;String&gt; strings = Arrays.asList(&quot;a1&quot;, &quot;a2&quot;, &quot;a3&quot;, &quot;b1&quot;, &quot;b2&quot;, &quot;b3&quot;);</span><br><span class="line">    List&lt;String&gt; filter = strings.stream().filter(str-&gt;str.startsWith(&quot;a&quot;)).collect(Collectors.toList());</span><br><span class="line">    System.out.println(filter);</span><br><span class="line">```  </span><br><span class="line"></span><br><span class="line">先让字符向量变成流(`stream()`)，然后设置过滤条件(`filter()`)，最后收集(`collect(Collectors.toList())`)</span><br><span class="line"></span><br><span class="line">2. StringBuilder</span><br></pre></td></tr></table></figure>

<pre><code>StringBuilder sb = new StringBuilder();
System.out.println(sb);
sb.append(&quot;hello&quot;);
System.out.println(sb);//打印出来为hello</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">## **Date**和**SimpleDateFormat**</span><br><span class="line"></span><br><span class="line">建立SimpleDateFormat实例的时候要写出结构</span><br><span class="line"></span><br><span class="line">例：</span><br></pre></td></tr></table></figure>

<p>SimpleDateFormat sdf = new SimpleDateFormat(“yyyy/MM/dd HH:mm:ss”);</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">### Date常用方法</span><br><span class="line"></span><br><span class="line">1. getTime：获取毫秒数，返回值为long</span><br><span class="line"></span><br><span class="line">2. Date1.before(Date2)：比较Date1是否在Date2之前</span><br><span class="line"></span><br><span class="line">3. Date1.after(Date2)：比较Date1是否在Date2之后</span><br><span class="line"></span><br><span class="line">### SimpleDateFormat常用方法</span><br><span class="line"></span><br><span class="line">1. format(Date实例)：获取格式时间（建立实例时设置格式）</span><br></pre></td></tr></table></figure>

<p>sdf.format(day1)</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">2. parse()：括号里为格式型的时间字符串，返回值为Date</span><br></pre></td></tr></table></figure>

<p>Date day2 = sdf.parse(“1988/5/3 15:23:16”);<br>```</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2019/07/16/Java知识点-1/" data-id="ck4r400rc007al0w0kh3ngiyn" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Java/">Java</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2019/07/20/Java知识点-2/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Java知识点-week2（枚举，继承）
        
      </div>
    </a>
  
  
    <a href="/2019/07/15/CSS额外知识点-选择器（下）/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">CSS额外知识点--选择器（下）</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Ajax/">Ajax</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/CSS/">CSS</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/CSS3/">CSS3</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Dart/">Dart</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Flutter/">Flutter</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/HTML/">HTML</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/HTML5/">HTML5</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/JSON/">JSON</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/QT/">QT</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/React/">React</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Sass/">Sass</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/TheKnowledgeOf/">TheKnowledgeOf</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/TypeScript/">TypeScript</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/bootstrap/">bootstrap</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/jQuery/">jQuery</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Ajax/">Ajax</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CSS/">CSS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CSS3/">CSS3</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Dart/">Dart</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Flutter/">Flutter</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/HTML/">HTML</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/HTML5/">HTML5</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JSON/">JSON</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/">Java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Javascript/">Javascript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/QT/">QT</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React/">React</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Sass/">Sass</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TheKnowledgeOf/">TheKnowledgeOf</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TypeScript/">TypeScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/bootstrap/">bootstrap</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jQuery/">jQuery</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Ajax/" style="font-size: 12.22px;">Ajax</a> <a href="/tags/CSS/" style="font-size: 18.89px;">CSS</a> <a href="/tags/CSS3/" style="font-size: 17.78px;">CSS3</a> <a href="/tags/Dart/" style="font-size: 14.44px;">Dart</a> <a href="/tags/Flutter/" style="font-size: 16.67px;">Flutter</a> <a href="/tags/Git/" style="font-size: 12.22px;">Git</a> <a href="/tags/HTML/" style="font-size: 14.44px;">HTML</a> <a href="/tags/HTML5/" style="font-size: 12.22px;">HTML5</a> <a href="/tags/JSON/" style="font-size: 10px;">JSON</a> <a href="/tags/Java/" style="font-size: 11.11px;">Java</a> <a href="/tags/JavaScript/" style="font-size: 20px;">JavaScript</a> <a href="/tags/Javascript/" style="font-size: 10px;">Javascript</a> <a href="/tags/QT/" style="font-size: 12.22px;">QT</a> <a href="/tags/React/" style="font-size: 15.56px;">React</a> <a href="/tags/Sass/" style="font-size: 11.11px;">Sass</a> <a href="/tags/TheKnowledgeOf/" style="font-size: 11.11px;">TheKnowledgeOf</a> <a href="/tags/TypeScript/" style="font-size: 10px;">TypeScript</a> <a href="/tags/bootstrap/" style="font-size: 11.11px;">bootstrap</a> <a href="/tags/jQuery/" style="font-size: 13.33px;">jQuery</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">December 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">November 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">October 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">September 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">August 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">July 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">June 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">May 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">April 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2019/12/29/Flutter-MaterialApp常用属性介绍/">Flutter-MaterialApp常用属性介绍</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-ListView/">Flutter-ListView</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-AppBar/">Flutter-AppBar</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-TabBar/">Flutter-TabBar</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-按钮/">Flutter-按钮</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>